<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Comments extends API_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('comments_model');
    }

    /**
    * 评论
    */
    public function save_comments()
    {
    	$site_id = $this->input->post('site_id', TRUE);
    	$star = $this->input->post('star', TRUE);
    	$contents = $this->input->post('contents', TRUE);
    	if(!$site_id){ echo "评论出现异常!"; exit;}
    	if(!$contents){echo "请填写评论内容";exit;}
    	$data = array(
    		'site_id' => $site_id,
    		'star' => $star,
    		'contents' => $contents,
    		'create_time' => time(),
    	);
    	$insert_id = $this->comments_model->insert($data);
    	if($insert_id){
    		echo "评论成功";
    	}else{
    		echo "网络出现异常，请稍后再试!";
    	}
    	exit;
    }

    /**
     * 评论列表
     */
	public function get_comments()
	{
		$site_id = $this->input->post('site_id', TRUE);
		if(!$site_id){
			echo false;exit;
		}
		$result = $this->comments_model->get_comments_by_id($site_id);
		if($result) {
			echo json_encode($result);
		}else{
			echo false;
		}
	}
}